import router from './router'
import {getSessionStorage} from "@/utils/sessionStorage.js"
import Store from "./store"

const whiteList = ['/login'] // 白名单
router.beforeEach((to, from, next) => {
    const hasToken = getSessionStorage()
  
    if (hasToken) {
      if (to.path === '/login') {
        Store.commit("dynamicRouter","manager")//鉴权测试//可以输入的值有common/Administrator/manager

        next({ path: '/' })
      } else {
        Store.commit("dynamicRouter","manager")//鉴权测试

       next()
      }
    } else {
  
      if (whiteList.indexOf(to.path) !== -1) {
        next()
      } else {
        next(`/login?redirect=${to.path}`)
      }
    }
  })
  
  router.afterEach(() => {
  })
  